package com.ct.controller;

import cn.hutool.core.map.MapUtil;
import cn.hutool.log.StaticLog;
import com.ct.R.Result.Result;
import com.ct.R.Result.ResultEnum.ResultCodeEnum;
import com.ct.controller.BaseController.BaseController;
import com.ct.model.User;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * 系统用户
 */
@RestController
//@RequestMapping("/user")
public class UserController extends BaseController {

    /**
     * 获取用户信息
     * 根据id查询用户信息
     * @param userId 用户id
     * @return 返回用户信息
     */
    @GetMapping("/getUser/{userId}")
    public Map getUser(@PathVariable("userId") Integer userId) {
        return  MapUtil.builder(new HashMap<String, String>())
                .put("name", "张三")
                .put("age", "13")
                .put("order", "1").build();
    }

    @GetMapping("/getUser")
    public String getUser( @RequestParam Map<String, String> params) {
        StaticLog.info("请求进入-{}",params);

        return MapUtil.getStr(params,"echostr");
    }


    /**
     * 保存用户信息
     * @param user 用户DTO
     * @return R
     */
    @PostMapping("/save")
    public Result saveUser(@RequestBody User user) {
        if(user!=null){
            return Result.fail(ResultCodeEnum.SERVER_ERROR);
        }
        return Result.success(user);
    }


}
